package cn.tx;

import javax.swing.*;
import javax.tools.Tool;
import java.awt.*;

public class MyDrawPanel extends JFrame{
    public static void main(String[] args) {
        new MyDrawPanel().init();
    }
    public void init(){
        this.setTitle("Ni's Drawing Board");
        this.setSize(800,600);
        this.setLocationRelativeTo(null);//把窗体显示在屏幕中间
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//设置窗体关闭按钮
        /*遵守GUI布局规则*/
        this.setLayout(new BorderLayout());

        //创建画布
        DrawPanel dp = new DrawPanel();
        //创建工具栏
        ToolsPanel tp = new ToolsPanel();
        //添加窗口
        this.add(tp,BorderLayout.WEST);
        this.add(dp,BorderLayout.EAST);

        this.setVisible(true);//设置窗体的可见性

        DrawListener dl = new DrawListener(tp,dp);
        //设置画布上的监听事件，鼠标的事件
        dp.addMouseListener(dl);
        //添加面板鼠标事件的监控器
        dp.addMouseMotionListener(dl);

    }
}
